<?php

/**
 * Description of LinkAnalyze
 *
 * @author  赵福堂
 */
class LinkAnalyze {
    public function doStart($array){
        if(is_array($array)){
            
            foreach($array as $key=>$val){                
                $link   =   file_get_contents($val);
                $fileName   =   Core::setFileName(Core::$downloadPath['link'] , $link);                
                $fileName_ex    =   $filename_ex   = explode(".",$fileName);                
                if($filename_ex[1] == "css"){ 
                     $patterns = '/url\([\"|\']?((.+)[jpg|gif|png][\?]?[^\)]{1,30})[\"|\']?\)/U'; //正则根据不同地址需要变换 
                     preg_match_all($patterns, $link, $matches); 
                    $imagesUrls = $matches[1];
                    
                     foreach($imagesUrls as $key=>$image){             
                        $link = str_replace( $image , "../".  Core::$downloadPath['link'] . basename($image) ,$link);                        
                        $downloadFile[ Core::$downloadPath['img'] . basename($image)]   =   Core::setFilePath($image , dirname($val));                       
                     }
                     $hockClass  =   Core::getClass('DefaultAnalyze');
                     $hockClass->doStart($downloadFile); 
                }
                if(!Core::saveData($key, $link)){
                     Core::setError("{$key} 下载失败！");
                }
            }
            
            
        }
       
    }
}
